package com.Hsu.demo.proxy;

import net.sf.cglib.proxy.Enhancer;
import org.springframework.aop.Advisor;
import org.springframework.aop.TargetSource;
import org.springframework.aop.framework.*;
import org.springframework.aop.framework.autoproxy.AutoProxyUtils;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.core.NativeDetector;
import org.springframework.core.SmartClassLoader;
import org.springframework.util.ClassUtils;

import java.io.Serializable;
import java.lang.reflect.Proxy;

/**
 * @author Hsu琛君珩
 * @ClassName:Main
 * @date 2024-01-17
 * @apiNote
 * @Version: v1.0
 */

public class Main {
    public static void main(String[] args) {
        //目标对象
        HouseSubject target = new RealHouseSubject();

        //目标对象2
        HouseSubjectClass houseSubjectClass = new HouseSubjectClass();

        //静态代理
        //HouseProxy proxy=new HouseProxy(subject);
        //proxy.rentHouse();
        //proxy.saleHouse();

        //JDK动态代理
        //HouseSubject proxy= (HouseSubject) Proxy.newProxyInstance(
        //        target.getClass().getClassLoader(),
        //        new Class[]{HouseSubject.class},
        //        new JDKInvocation(target)
        //);
        //proxy.rentHouse();
        //proxy.saleHouse();

        //HouseSubjectClass proxy2 = (HouseSubjectClass) Proxy.newProxyInstance(
        //        houseSubjectClass.getClass().getClassLoader(),
        //        new Class[]{HouseSubjectClass.class},
        //        new JDKInvocation(houseSubjectClass)
        //);
        //proxy2.rentHouse();

        //CGLib动态代理
        //HouseSubject proxy2= (HouseSubject) Enhancer.create(target.getClass(),new CGLibIntercepter(target));
        //proxy2.rentHouse();
        //proxy2.saleHouse();

        //CGLib代理类
        HouseSubjectClass proxy3 = (HouseSubjectClass) Enhancer.create(houseSubjectClass.getClass(), new CGLibIntercepter(houseSubjectClass));
        proxy3.rentHouse();
    }
}